<template>
	<view v-if="list" class="content poRel">
		<scroll-view style="height: calc(100vh);" class="wid100" scroll-y="true">
			<view style="height: 1rpx;"></view>
			<wsj v-if="list.length == 0 && list.other_city.length == 0 && xuan == 0" zs='0'></wsj>
			<block v-for="(item,index) in list.this_city" :key="index">
				<view class="wid90 mar borRad20 bacFFF mar-top30" @click="xuanClick(item)"
					style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);padding: 30rpx 0;">
					<view class="wid90 mar">
						<view class="dis disAl ">
							<view class="foSi40 fowe600" style="line-height: 40rpx;">{{item.name}}</view>
							<view class="foSi30 fowe600 mar-left30" style="color: #737373;">{{item.mobile}}</view>
						</view>
						<view class="mar-top20 foSi25 overflowHidden" style="color: #737373;">{{item.address}}{{item.address_info}}</view>
					</view>
				</view>
			</block>
			<view class="wid90 mar" style="height: 100rpx; line-height: 150rpx; font-weight: 800; color: #636363;" v-if="list.other_city.length > 0">
				超出范围不可选地址
			</view>
			<block v-for="(item,index) in list.other_city" :key="index">
				<view class="wid90 mar borRad20 bacFFF mar-top20"
					style="box-shadow: 0rpx 0rpx 10rpx 0rpx rgba(0,0,0,0.1);padding: 30rpx 0;">
					<view class="wid90 mar">
						<view class="dis disAl ">
							<view class="foSi40 fowe600" style="line-height: 40rpx; color:#d4d4d4;">{{item.name}}</view>
							<view class="foSi30 fowe600 mar-left30" style="color: #d4d4d4;">{{item.mobile}}</view>
						</view>
						<view class="mar-top20 foSi25 overflowHidden" style="color: #d4d4d4;">{{item.address}}{{item.address_info}}</view>
					</view>
				</view>
			</block>
			<view style="height: 140rpx;"></view>
		</scroll-view>
		<view class="poFix wid100 dis disAl disJuC bacFFF" style="height: 124rpx;border-top: 1rpx solid #878787;bottom: 0;z-index: 10;">
			<view class="hei80 dis disAl disJuC borRad40 coFFF foSi35 fowe600" @click="tiaozhuan('/pages/wode/addressAdd')"
				style="width: 450rpx;" :style="'background-color: '+theme.main_color+';'">新增地址</view>
		</view>
	</view>
</template>

<script>
	import wsj from '../common/w_sj.vue'
	export default {
		components: {
			wsj
		},
		data() {
			return {
				url: this.global.url,
				xuan: null,
				id: '',
				last_page: 0,
				page: 1,
				quantity: 1,
				list: null,
				theme: null
			}
		},
		onLoad() {},
		onShow() {
			this.getList()
			this.theme = uni.getStorageSync('theme')
		},
		methods: {
			shuanchu(index){
				var that = this;
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/address/del',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						id : that.list[index].id
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							that.list.splice(index, 1);
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
			},
			xuanClick(item){
				uni.$emit('addressClick',item)
				uni.navigateBack(1)
			},
			getList(){
				var that = this;
				uni.request({
					url: that.global.url + 'api/qianyu_smfw/address/lists',
					method: "POST",
					header: {
						'site-id': that.global.site_id, //自定义请求头信息
						'token': uni.getStorageSync('token')
					},
					data: {
						'city_title':uni.getStorageSync('city').title
					},
					success(res) {
						let result = res.data
						if (result.code == 1) {
							if(that.page == 1){
								that.list = result.data
								console.log(that.list)
							}else{
								that.list = that.list.concat(result.data)
							}
						}else{
							uni.showToast({
								title: result.msg,
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							}) 
						}
					}
				})
				
			},
			fanhui(){
				uni.navigateBack(1)
			},
			tiaozhuan(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.content {
		min-height: 100vh;
	}
	.xia{
		height: 1rpx;
		background-color: #E1DFDF;
	}
</style>